package com.linux.huhx.thread3.threadState_1;

import java.util.concurrent.TimeUnit;

/**
 * @Author: huhx
 * @Date: 2017-10-31 下午 2:57
 * STATE: TIMED_WAITING, BLOCKED
 */
public class StateRun3 {

    public static void main(String[] args) throws InterruptedException {
        Thread1 threadA = new Thread1();
        threadA.setName("A");
        threadA.start();

        Thread2 threadB = new Thread2();
        threadB.setName("B");
        threadB.start();

        TimeUnit.SECONDS.sleep(2);
        System.out.println("In main threadB " + threadB.getState());
        System.out.println("In main threadA " + threadA.getState());
    }

    static class Thread1 extends Thread {
        @Override
        public void run() {
            Service.serviceMethod();
        }
    }

    static class Thread2 extends Thread {
        @Override
        public void run() {
            Service.serviceMethod();
        }
    }
}

class Service {
    public synchronized static void serviceMethod() {
        try {
            System.out.println(Thread.currentThread().getName() + " enter service method.");
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
/*
A enter service method.
In main threadB BLOCKED
In main threadA TIMED_WAITING
B enter service method.
 */
